﻿using System;
using DyUi.Base.Constants;
using DyUi.Base.Interfaces;
using DyUi.Base.Interfaces.SubSystems;
using DyUi.Core.Services;

namespace DyUi.Core.SubSystems
{
    public class ServiceSubSystem : DyUiControllerSubSystem, IServiceSubSystem
    {
        public IDyUiServiceLocator LoadServiceLocator(IDyUiComponent component)
        {
            var serviceLocator = new DyUiServiceLocator();

            serviceLocator.SetService(ServiceNames.FactoryService, new FactoryService());
            serviceLocator.SetService(ServiceNames.MessageService, new MessageService());
            serviceLocator.SetService(ServiceNames.LoggingService, new LoggingService());
            serviceLocator.SetService(ServiceNames.ExecutionService, Controller.ExecutionSubSystem.ResolveExecutionHost(component));

            foreach (var service in serviceLocator.Services)
            {
                if (service != null)
                {
                    service.Component = component;
                    service.Controller = Controller;
                    service.Prepare();
                }
            }

            return serviceLocator;
        }

        public void DestroyAppletInstance(Object arg)
        {

        }
    }
}
